package com.yuchen.ishop.web.app.goods;


import com.yuchen.ishop.entity.GoodsImg;
import com.yuchen.ishop.service.file.FileRestClient;
import com.yuchen.ishop.service.goods.GoodsImgRestClient;
import com.yuchen.ishop.web.BaseAction;
import com.yuchen.jaxrs.Responses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

/**
 * 商品
 */
@Controller
@RequestMapping(value = "/goods")
public class GoodsAction extends BaseAction {

    @Autowired
    private GoodsImgRestClient goodsImgRestClient;

    @Autowired
    private FileRestClient fileRestClient;

   /* @Autowired
    private GoodsRestClient goodsRestClient;*/


    @RequestMapping(value = "/deleteGoodsImg", method = RequestMethod.POST)
    @ResponseBody
    public Responses deleteGoodsImg(Long id){
        GoodsImg goodsImg = goodsImgRestClient.get(id);
        Responses responses = goodsImgRestClient.delete(id);
        if(responses.isStatus()){
            fileRestClient.deleteFile(goodsImg.getImageUrl());
        }
        return responses;
    }

    //主图设置
    @RequestMapping(value = "/changeGoodsImgType", method = RequestMethod.POST)
    @ResponseBody
    public Responses changeGoodsImgType(Long id,String allIds){
        Responses responses = goodsImgRestClient.changeGoodsImgType(id, allIds);
        return responses;
    }

    @RequestMapping(value = "/showGoodsImg", method = RequestMethod.POST)
    @ResponseBody
    public Responses showGoodsImg(Long goodsId){
        return goodsImgRestClient.showGoodsImg(goodsId);
    }


    /*@RequestMapping(value = "/deleteAllGoodsImg", method = RequestMethod.POST)
    @ResponseBody
    public Responses deleteAllGoodsImg(String ids){
        return goodsImgRestClient.deleteAll(ids);
    }*/

}
